package deepbrain.simnetwork.engine;

import java.util.Collection;

import deepbrain.simnetwork.task.Task;

/**
 * SimpleSimEngine represents a very simple engine, which only invoke tasks in
 * current thread and the tasks cannot be terminated safely.
 * 
 * 
 * @author Li Yang
 * @create 2009-2-25
 */
public class SimpleSimEngine implements SimEngine {

	private boolean open = true;

	public void runTask(Task task) {
		if (!open)
			throw new IllegalStateException("Cannot run new tasks after");
		task.setThreadLocalEngine(this);
		task.run();
	}

	public void runTasks(Collection<Task> tasks) {
		for (Task task : tasks)
			runTask(task);
	}

	public void stop() {
		throw new UnsupportedOperationException(
				"Cannot Stop Tasks in SimEngine, Please Try Ctrl+C");
	}

	public void shutdown() {
	}

}
